<?php
/**
 * User_AdminController
 *
 * @author
 * @version
 */

class User_AdminController extends Zen_Controller_Admin
{
	public $columns = array(
	array('name'=>'login','index'=>'login','label'=>'Логин'),
	array('name'=>'name','index'=>'name','label'=>'Имя')
	);


	public function indexAction() {
		$this->view->model=new User_Model_Users();
		$this->view->columns = $this->columns;
	}

	public function formAction(){
		$params=$this->_getAllParams();
		$form=new User_Form_User();
		if(isset($params ['pass'])){
			if (trim ( $params ['pass'] ) == '') {
				$form->getElement ( 'pass' )->setRequired ( false );
				$form->getElement ( '_confirm_approve' )->setRequired ( false );
				$form->removeElement('pass');
				unset($params['pass']);	
			}
		}

		if(isset($params ['id'])){
			$user = Zen_User::getOne (preg_replace('/\D/','', $params['id']));
			if(isset($params ['login'])){
				if ($params ['login'] == $user ['login']) {
					$form->getElement ( 'login' )->removeValidator ( 'NoDbRecordExists' );
				}
			}
			if(isset($params ['email'])){
				if ($params ['email'] == $user ['email']) {
					$form->getElement ( 'email' )->removeValidator ( 'NoDbRecordExists' );
				}
			}
		}

		$this->_helper->jqgrid(
		new User_Model_Users(),
		$params,
		$this->columns,
		$form
		);
	}
}